﻿
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>任务字典管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="../../../layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="../../../layuiadmin/style/admin.css" media="all">
    <script src="../../../layuiadmin/lib/jquery.min.js"></script>
    <script src="../../../layuiadmin/lib/api.js"></script>
    <script src="../../../layuiadmin/artdialog/artDialog.js?skins=chrome"></script>
    <script src="../../../layuiadmin/lib/common.js"></script>
    <script src="../../../layuiadmin/layui/layui.js"></script>
    <script src="../../../layuiadmin/lib/system.js"></script>
    <script>
        //检查服务器是否已登录，没有登录则跳转至登录页。
        sys_islogin();
    </script>

</head>
<body>

    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">

                    <div class="layui-inline">
                        <label class="layui-form-label">名称</label>
                        <div class="layui-input-inline">
                            <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    
                    <div class="layui-inline">
                        <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="search-btn">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>

            <div class="layui-card-body">
                <div style="padding-bottom: 10px;">
                    <button class="layui-btn layuiadmin-btn-list" data-type="batchdel">删除</button>
                    <button class="layui-btn layuiadmin-btn-list" data-type="add">添加</button>
                </div>
                <table id="LAY-app-content-list" lay-filter="LAY-app-content-list"></table>

                <script type="text/html" id="table-content-list">
                    <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="edit"><i class="layui-icon layui-icon-edit"></i>编辑</a>
                    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del"><i class="layui-icon layui-icon-delete"></i>删除</a>
                </script>
            </div>
        </div>
    </div>

    
    <script>
  layui.config({
    base: '../../../layuiadmin/' //静态资源所在路径
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'contlist', 'table','laydate'], function(){
      var table = layui.table, form = layui.form;
      var date = new Date();

    //监听搜索
      form.on('submit(search-btn)', function(data){
        var field = data.field;
        console.log(data.field);
      //执行重载
      table.reload('LAY-app-content-list', {
        where: field
      });
    });


      //列表管理
      table.render({
          elem: '#LAY-app-content-list'
          , url: '/TaskDicMerber/TaskDicList' //接口
          ,align:'center'
          , cols: [[
              { type: 'checkbox', fixed: 'left',field: 'ID' }
              
              , { field: 'CODE', title: '编码', align: 'center', sort: true,}
              , {
                  field: 'CODENAME', title: '名称', templet: '#datetype_span', align: 'center',
                  templet: function (d) {                     
                      return "<span style='color:" + d.COLOR + "'>" + d.CODENAME+"</span>";
                  }
              }
              , {
                  field: 'TYPE', title: '类型', align: 'center',
                  templet: function (d) {
                      var str = "";
                      if (d.TYPE == 1) str = "任务状态";
                      else if (d.TYPE == 2) str = "任务等级";
                      else if (d.TYPE == 3) str = "任务标签";
                      return str;
                  }
              }
              , { field: 'SORTINDEX', title: '排序', sort: true, align: 'center' }
              , { title: '操作', minWidth: 180, align: 'center', fixed: 'right', toolbar: '#table-content-list' }
          ]]
          , page: true
          , limit: 15
          , where: {

          }
          , limits: [10, 15, 20, 25, 30]
          , text: {
              none: '暂无相关数据'
          }
      });

      //监听表格的操作栏
      table.on('tool(LAY-app-content-list)', function (obj) {
          var data = obj.data;

          if (obj.event === 'del') {
              layer.confirm('当前删除项关联有其他数据，请谨慎操作，确定删除吗？', function (index) {

                  var isSucss = fun_del(data.ID);
                  if (isSucss>0) {
                      table.reload('LAY-app-content-list');
                      layer.msg('成功删除 ' + isSucss + " 数据");
                  }
                  layer.close(index);
              });
          } else if (obj.event === 'edit') {
              layer.open({
                  type: 2
                  , title: '编辑项目字典'
                  , content: 'dicform.html'
                  , maxmin: true
                  , area: ['660px', '600px']
                  , success: function (layero, index) {
                      var iframe = window['layui-layer-iframe' + index];
                      // 向子页面的全局函数child_select_user传参
                      iframe.child_fill_data(data);
                  }

              });
          }
      });

    //表格上方的操作
    var $ = layui.$, active = {
        batchdel: function () {
            var checkStatus = table.checkStatus('LAY-app-content-list')
                , checkData = checkStatus.data; //得到选中的数据
            console.log(checkData);
            if (checkData.length === 0) {
                return layer.msg('请选择数据');
            }

            layer.confirm('当前删除项关联有其他数据，请谨慎操作，确定删除吗？', function (index) {
                var ids = "";
                for (var i = 0; i < checkData.length; i++) {
                    ids += checkData[i].ID + ",";
                }
                var count = fun_del(ids);
                table.reload('LAY-app-content-list');
                layer.msg('成功删除 ' + count + " 数据");

        });
      },
      add: function(){
        layer.open({
          type: 2
          ,title: '添加项目字典'
          ,content: 'dicform.html'
          ,maxmin: true
          ,area: ['660px', '600px']

        });
      }
    };

    $('.layui-btn.layuiadmin-btn-list').on('click', function(){
      var type = $(this).data('type');
      active[type] ? active[type].call(this) : '';
    });

  });

        //删除
        function fun_del(ids) {
            var isSucc = 0;
            $.ajax({
                url: "/TaskDicMerber/DeleteTaskDic",    //请求的url地址
                dataType: "json",   //返回格式为json
                async: false,//请求是否异步，默认为异步，这也是ajax重要特性
                data: { delIds: ids },    //参数值
                type: "POST",   //请求方式
                success: function (data) {
                    //请求成功时处理
                    isSucc = data;
                },

                error: function (res) {
                    layer.msg("删除失败，请联系技术人员");
                }
            });
            return isSucc;
        };
    </script>
</body>
</html>
